package com.itany.corejava.code09_集合.list集合;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月20日 10:18
 */
public class Test02_ArrayList {
    public static void main(String[] args) {
        listToArray();
        // arrayToList();
    }
    public static void listToArray(){

        ArrayList list=new ArrayList();
        // ArrayList<String> list=new ArrayList();
        list.add("admin");
        // list.add(100);
        // list.add("cici");
        // list.add(true);
        // list.add("coco");
        System.out.println(list);

        //通过toArray，将一个ArrayList集合转换成数组
        Object[] arr=  list.toArray();
        System.out.println(Arrays.toString(arr));

    }


    public static void arrayToList(){
        String[] arr={"admin","jack","tom","lili"};

        //将数组转换成集合
        List<String> list=Arrays.asList(arr);
        System.out.println(list);

        List<Integer> list2=Arrays.asList(12,23,34,54,56);//直接以逗号隔开
        System.out.println(list2);

        List<String> list3=Arrays.asList("aa","bb","cc");
        System.out.println(list3);
        List<String> list4=Arrays.asList("alice","cici","coco","cici","tom");
        System.out.println(list4);

        ArrayList<String> names=new ArrayList<>(list4);
        names.remove("cici");
        System.out.println(names);


        List<String> list5=Arrays.asList("aaa","bbb","ccc");

        //此时list5并不是ArrayList，删除时会报错
        // list5.remove("aaa");//java.lang.UnsupportedOperationException
        System.out.println(list5);





    }
}
